{include file="header.htm" /}
<body class="bodystyle" style="overflow-y: scroll; cursor: default; -moz-user-select: inherit;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    {include file="bar.htm" /}
    <form class="form-horizontal" id="post_form" action="{:weapp_url('AirBottle/AirBottle/add')}" method="post">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="name"><em>*</em>厂家名称</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="row[name]" value="{$row.name}" id="name" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="address"><em>*</em>厂家地址</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="row[address]" value="{$row.address}" id="address" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="phone"><em>*</em>联系电话</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="row[phone]" value="{$row.phone}" id="phone" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>

            <div class="bot">
                <a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
            </div>
        </div>
    </form>
</div>
<script src="__WEAPP_TEMPLATE__/skin/js/jquery.validate.min.js"></script>
<script type="text/javascript">
    $(function () {
        //表单数据校验
        $("#post_form").validate({
            ignore: ":hidden:not(select)",//解决无法校验select
            errorElement: "span",
            rules: {
                'row[name]':"required",
                'row[address]':"required",
                'row[phone]':"required",

            },
            messages: {
                'row[name]':"厂家名称不能为空",
                'row[address]':"厂家地址不能为空",
                'row[phone]':"联系电话不能为空",
            }
        });

    });
    // 判断输入框是否为空
    function checkForm(){
        /* if($("#post_form").valid()){
             layer_loading('正在处理');
             $('#post_form').submit();
         }*/
        if($("#post_form").valid()){
            layer_loading('正在处理');
            //$('#post_form').submit();
            var data = $("#post_form").serialize();
            $.ajax({
                type: "POST",        // 请求方式
                url: "{:weapp_url('AirBottle/AirBottle/factory')}", // 请求路径
                dataType: "json",   // 预期返回一个 json 类型数据
                data:data,
                success: function (ret) {   // data是形参名，代表返回的数据
                    console.log(ret);
                    if(ret.code==1){
                        //layer.alert('添加成功');
                        layer.alert(ret.msg, { icon: 1, closeBtn: 0 }, function (index) {
                            window.parent.location.reload();
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });

                    }else{
                        layer.msg('更新失败', {icon:2});
                    }
                }
            })
        }
    }

    function img_call_back(fileurl_tmp)
    {
        $("#logo_local").val(fileurl_tmp);
        $("#img_a_local").attr('href', fileurl_tmp);
        $("#img_i_local").attr('onmouseover', "layer_tips=layer.tips('<img src="+fileurl_tmp+" class=\\'layer_tips_img\\'>',this,{tips: [1, '#fff']});");
    }
</script>
{include file="footer.htm" /}